package com.ccp.dev.qbdms.controller;

import com.alibaba.fastjson.JSON;
import com.ccp.dev.core.basic.annotion.Action;
import com.ccp.dev.core.basic.base.BaseController;
import com.ccp.dev.core.basic.consts.UrlConstants;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.util.RequestUtil;
import com.ccp.dev.core.util.log.SysAuditThreadLocalHolder;
import com.ccp.dev.qbdms.model.WQbdXhdh;
import com.ccp.dev.qbdms.model.vo.ModelQualityStatisticsParamVo;
import com.ccp.dev.qbdms.service.ModelQualityStatisticsService;
import com.ccp.dev.qbdms.service.WQbdXhdhService;
import com.ccp.dev.qbdms.util.BaseUtil;
import com.ccp.dev.system.service.DictionaryService;
import com.ccp.dev.system.service.SysOrgService;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassDescribe:
 *
 * @author :milihao
 * @date :2019-07-20 Since:1
 */
@Controller
@Action(customModel = "型号质量问题统计")
@RequestMapping("/qbdms/modelQualityStatistics")
public class ModelQualityStatisticsController extends BaseController {

	@Resource
	private WQbdXhdhService wQbdXhdhService;
	@Resource
	private ModelQualityStatisticsService modelQualityStatisticsService;
	@Resource
	private DictionaryService dictionaryService;
	@Resource
	private SysOrgService sysOrgService;

	/**按阶段统计,对应的工作阶段取值 型号总装总测(调)*/
	private final String YZAJD_XHZZZC = "型号总装总测(调)";
	/**按阶段统计,对应的工作阶段取值 大型试验*/
	private final String YZAJD_DXSS = "大型试验";
	/**按阶段统计,对应的工作阶段取值 外场(用户)*/
	private final String YZAJD_WC = "外场(用户)";
	/**按阶段统计,对应的工作阶段取值 其他*/
	private final String YZAJD_QT = "其他";

	/**
	 * 功能描述: 跳转到型号质量问题统计首页
	 *
	 * @return: java.lang.String
	 * @auther: mlh
	 * @date: 2020-07-20 09:12:57
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/index")
	@Action(description = "跳转到型号质量问题统计首页", exectype = "页面跳转日志")
	public String index(ModelMap modelMap) {
		List<WQbdXhdh> wQbdXhdhs = wQbdXhdhService.getAll();
		modelMap.put("currentSystemLevel", BaseUtil.getCurrentSystemLevel());
		modelMap.put("wQbdXhdhs", JSON.toJSONString(wQbdXhdhs));
		modelMap.put("endTime",String.valueOf( Calendar.getInstance().get(Calendar.YEAR)));
		modelMap.put("beginTime",String.valueOf( Calendar.getInstance().get(Calendar.YEAR)-2));
		modelMap.put("tjfs", JSON.toJSONString(dictionaryService.getByNodeKey("tjfs")));
		modelMap.put("researchRoomList", JSON.toJSONString(sysOrgService
				.querySubSysOrgBySupOrgIdNoChild(sysOrgService.getSysOrgByOrgCode("wrj").getOrgId())));
		return "modelQualityStatistics/index";
	}

	/**
	 * 功能描述: 获取所有统计图数据
	 *
	 * @param: WQbdReportTemplate 实体
	 * @return: java.lang.Object
	 * @auther: milihao
	 * @date: 2020-06-23 15:26:43
	 */
	@RequestMapping("/getChartData")
	@ResponseBody
	@Action(description = "获取统计图数据", detail = "获取所有统计图数据<#if success>成功<#else>失败</#if>")
	public Object getCharData(ModelQualityStatisticsParamVo modelQualityStatisticsParamVo,HttpServletRequest request) {
		QueryFilter queryFilter = new QueryFilter(request, false);
		List<Map<String, Object>> dataMapList = modelQualityStatisticsService
				.getChartData(modelQualityStatisticsParamVo,queryFilter);
		SysAuditThreadLocalHolder.putParamerter("success", true);
		return success(dataMapList);
	}

	/**
	 * 功能描述: 跳转到型号质量列表页
	 *
	 * @return: java.lang.String
	 * @auther: mlh
	 * @date: 2020-07-20 09:12:57
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/list")
	@Action(description = "跳转到型号质量列表页", exectype = "页面跳转日志")
	public String list(ModelMap modelMap, HttpServletRequest request) {
		modelMap.put("title", RequestUtil.getString(request, "title"));
		modelMap.put("beginTime", RequestUtil.getString(request, "beginTime") + "-01-01");
		modelMap.put("endTime", RequestUtil.getString(request, "endTime") + "-12-31");
		modelMap.put("modelSymbol", RequestUtil.getString(request, "modelSymbol"));
		String dutyDept = RequestUtil.getString(request, "dutyDept", "");
		if (dutyDept.equals("undefined")) {
			dutyDept = "";
		}
		modelMap.put("dutyDept", dutyDept);
		modelMap.put("workPhaseType", RequestUtil.getString(request, "workPhaseType"));
		// 有值表示 按工作阶段统计
		int gzjd = RequestUtil.getInt(request, "gzjdlx", -1);
		// 来自点击的柱上类型或者饼图的类型
		String typestr = RequestUtil.getString(request, "fCausationclass1");
		if (gzjd != -1) {
			switch (typestr) {
				case YZAJD_XHZZZC:
					// 型号总装总测(调)
					modelMap.put("gzjd", "'导弹总装','地面设备总装','发动机总装'");
					break;
				case YZAJD_DXSS:
					// 大型试验
					modelMap.put("gzjd","'分系统试验','地面试验','飞行试验'");
					break;
				case YZAJD_QT:
					// 其他
					modelMap.put("gzjd","'产品生产'");
					break;
				case YZAJD_WC:
					// 外场(用户)
					modelMap.put("gzjd","'交付使用'");
					break;
			}
		}
		else{
			modelMap.put("fCausationclass1", RequestUtil.getString(request, "fCausationclass1"));
		}
		return "modelQualityStatistics/list";
	}

}
